<template>
  <div class="app-container">
    <ViewSessions
      class="sousuo"
      style="margin-bottom: 15px"
      @selected="selected"
      @add="add"
    />
    <el-table
      :row-class-name="tableRowClassName"
      :data="productList"
      :header-row-style="{
        'background-color': '#E6E6E6',
        'font-weight': 'bold',
        color: '#333',
      }"
      :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
      style="width: 100%; margin-bottom: 20px"
      row-key="id"
    >
      <el-table-column show-overflow-tooltip align="center" prop="id" label="编号"/>
      <el-table-column show-overflow-tooltip align="center" prop="insideCode" label="产品编号"/>
      <el-table-column show-overflow-tooltip align="center" prop="cost" label="预估成本"/>
      <el-table-column show-overflow-tooltip align="center" prop="process" label="工序总览"/>
      <!-- <el-table-column show-overflow-tooltip align="center" prop="completionRate" label="已完成率"/> -->
      <el-table-column align="center" label="文件">
        <template slot-scope="scope">
          <el-button
            type="text"
            size="mini"
            @click="() => seeOrder(scope.row)"
          >查看
          </el-button>
        </template>
      </el-table-column>
      <el-table-column align="center" label="订单二维码">
        <template slot-scope="scope">
          <el-button
            type="text"
            size="mini"
            @click="() => seeVueQr(scope.row)"
          >查看
          </el-button>
        </template>
      </el-table-column>
      <!-- <el-table-column align="center" prop="orgerCode" label="订单二维码"/> -->
      <el-table-column v-if="isNoOutsourcing" show-overflow-tooltip align="center" prop="purchaseRequisition" label="请购单号">
        <template slot-scope="scope">
          <el-button
            type="text"
            size="mini"
            @click="() => addRequisition(scope.row)"
          >{{ scope.row.purchaseRequisition }}
          </el-button>
        </template>
      </el-table-column>
      <!-- <el-table-column show-overflow-tooltip align="center" prop="intoDate" label="到库日期"/> -->
      <!-- <el-table-column show-overflow-tooltip align="center" prop="isArrival" label="是否到库"/> -->
      <el-table-column v-if="this.$route.query.id" show-overflow-tooltip align="center" prop="orderCode" label="所属订单"/>
      <!-- <el-table-column show-overflow-tooltip align="center" prop="isLeaflets" label="是否派单"/> -->
      <el-table-column v-if="isNoOutsourcing" align="center" label="派单">
        <template slot-scope="scope">
          <el-button
            type="text"
            size="mini"
            @click="() => seeDispatch(scope.row)"
          >查看
          </el-button>
        </template>
      </el-table-column>
      <el-table-column show-overflow-tooltip align="center" prop="isAssist" label="外协否">
        <template slot-scope="scope">
          <span v-if="scope.row.isAssist == 0">{{ scope.row.isAssist == 0 ? '否' : '' }}</span>
          <el-button
            v-if="scope.row.isAssist == 1"
            type="text"
            size="mini"
            @click="() => seeOutsourcing(scope.row)"
          >是
          </el-button>
        </template>
      </el-table-column>
      <el-table-column v-if="isNosingle" label="分单">
        <template slot-scope="scope">
          <el-button
            v-if="scope.row.isAssist != 0 && scope.row.isAssist != 1"
            type="text"
            size="mini"
            @click="() => single(scope.row)"
          >分单
          </el-button>
        </template>
      </el-table-column>
      <el-table-column show-overflow-tooltip align="center" label="状态">
        <template slot-scope="scope">
          <span>{{ scope.row.deleteFlag == 1 ? '删除' : '正常' }}</span>
        </template>
      </el-table-column>
      <el-table-column show-overflow-tooltip align="center" prop="deleteRemark" label="备注"/>
      <el-table-column fixed="right" align="center" label="操作">
        <template slot-scope="scope">
          <el-button
            v-if="scope.row.deleteFlag == 1"
            type="text"
            size="mini"
            @click="() => seeDeleteItem(scope.row)"
          >查看
          </el-button>
          <el-button
            v-if="scope.row.deleteFlag != 1 && isRouter"
            type="text"
            size="mini"
            @click="() => upload(scope.row)"
          >修改
          </el-button>
          <el-button
            v-if="scope.row.deleteFlag != 1 && isRouter"
            type="text"
            size="mini"
            @click="() => delect(scope.row)"
          >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      :current-page="page"
      :total="total"
      :page-size="limit"
      style="padding: 30px 0; text-align: end"
      layout="total, prev, pager, next,jumper"
      @current-change="fetchData"
    />
    <el-dialog
      :visible.sync="dialogFormVisible"
      :title="dialogFormValue"
      @close="closeDialog"
    >
      <el-form
        ref="product"
        :model="product"
        :rules="validateRules"
        label-width="130px"
        style="height: 550px; overflow: auto"
      >
        <el-form-item label="产品内部编号：" prop="insideCode">
          <el-col :span="12">
            <el-input
              :disabled="readonlyInput"
              v-model="product.insideCode"
              size="small"
              placeholder="请输入产品内部编号"
            />
          </el-col>
        </el-form-item>
        <el-form-item label="预估成本：" prop="cost">
          <el-col :span="12">
            <el-input
              :disabled="readonlyInput"
              v-model="product.cost"
              size="small"
              placeholder="请输入预估成本"
            />
          </el-col>
        </el-form-item>
        <el-form-item label="工序总览：" prop="process">
          <el-col :span="12">
            <el-input
              :disabled="readonlyInput"
              v-model="product.process"
              size="small"
              placeholder="请输入工序总览"
            />
          </el-col>
        </el-form-item>
        <div style="display: inline-flex;flex-flow: row wrap;align-items: center;">
          <el-form-item label="图片图纸：">
            <div>
              <el-upload
                :disabled="readonlyInput"
                :show-file-list="false"
                :http-request="myUploadImg"
                class="avatar-uploader"
                action="https://jsonplaceholder.typicode.com/posts/"
                accept=".jpg,.jpeg,.png,.JPG,.JPEG"
              >
                <div v-if="imageUrl" class="imageUrl">
                  <img :src="imageUrl" class="avatar" >
                  <b @click.stop="removeImg">x</b>
                </div>

                <i v-else class="el-icon-plus avatar-uploader-icon"/>
              </el-upload>
            </div>
          </el-form-item>
          <el-form-item>
            <div>
              <el-upload
                :disabled="readonlyInput"
                :show-file-list="false"
                :http-request="myUploadImgOne"
                class="avatar-uploader"
                action="https://jsonplaceholder.typicode.com/posts/"
                accept=".jpg,.jpeg,.png,.JPG,.JPEG"
              >
                <div v-if="imageUrlOne" class="imageUrlOne">
                  <img :src="imageUrlOne" class="avatar" >
                  <b @click.stop="removeImgOne">x</b>
                </div>
                <i v-else class="el-icon-plus avatar-uploader-icon"/>
              </el-upload>
            </div>
          </el-form-item>
        </div>
        <el-form-item label="pdf文件：">
          <div style="float: left; margin-right: 40px">
            <el-upload
              :disabled="readonlyInput"
              :http-request="myUploadPDF"
              :show-file-list="true"
              :file-list="fileList"
              :on-remove="onRemove"
              class="upload"
              action="upload"
              accept=".pdf"
            >
              <el-button size="small" type="primary">点击上传</el-button>
              <div slot="tip" class="el-upload__tip">只能上传PDF文件</div>
            </el-upload>
          </div>
        </el-form-item>
        <el-form-item label="pdf文件：">
          <div style="float: left; margin-right: 40px">
            <el-upload
              :disabled="readonlyInput"
              :http-request="myUploadStp"
              :show-file-list="true"
              :file-list="fileListStp"
              :on-remove="onRemoveStp"
              class="upload"
              action="upload"
              accept=".stp"
            >
              <el-button size="small" type="primary">点击上传</el-button>
              <div slot="tip" class="el-upload__tip">只能上传stp文件</div>
            </el-upload>
          </div>
        </el-form-item>
        <el-form-item label="请购单号：" prop="requisition">
          <el-col :span="12">
            <el-input
              :disabled="readonlyInput"
              v-model="product.requisition"
              size="small"
              placeholder="请输入请购单号"
            />
          </el-col>
        </el-form-item>
        <el-form-item label="项目号码：">
          <el-col :span="12">
            <el-input
              :disabled="readonlyInput"
              v-model="product.projectCode"
              size="small"
              placeholder="请输入项目号码"
            />
          </el-col>
        </el-form-item>
        <el-form-item label="产品编号：">
          <el-col :span="12">
            <el-input
              :disabled="readonlyInput"
              v-model="product.code"
              size="small"
              placeholder="请输入产品编号"
            />
          </el-col>
        </el-form-item>
        <el-form-item label="品名/规格：">
          <el-col :span="12">
            <el-input
              :disabled="readonlyInput"
              v-model="product.specifications"
              size="small"
              placeholder="请输入品名/规格"
            />
          </el-col>
        </el-form-item>
        <el-form-item label="数量：">
          <el-col :span="12">
            <el-input
              :disabled="readonlyInput"
              v-model="product.amount"
              size="small"
              placeholder="请输入数量"
            />
          </el-col>
        </el-form-item>
        <el-form-item label="单位：">
          <el-col :span="12">
            <el-input
              :disabled="readonlyInput"
              v-model="product.unit"
              size="small"
              placeholder="请输入单位"
            />
          </el-col>
        </el-form-item>

        <el-form-item label="订单日期：">
          <el-col :span="6">
            <el-date-picker
              :disabled="readonlyInput"
              v-model="product.date"
              value-format="yyyy-MM-dd"
              type="date"
              placeholder="选择订单日期"
            />
          </el-col>
        </el-form-item>
        <el-form-item label="采购单号：">
          <el-col :span="12">
            <el-input
              :disabled="readonlyInput"
              v-model="product.purchase"
              size="small"
              placeholder="请输入采购单号"
            />
          </el-col>
        </el-form-item>
        <el-form-item label="项次：">
          <el-col :span="12">
            <el-input
              :disabled="readonlyInput"
              v-model="product.purchaseItem"
              onkeyup="value=value.replace(/[^\d]/g,'')"
              size="small"
              placeholder="请输入项次"
            />
          </el-col>
        </el-form-item>
        <el-form-item label="工艺最近更改日：">
          <el-col :span="6">
            <el-date-picker
              :disabled="readonlyInput"
              v-model="product.workmanshipDate"
              value-format="yyyy-MM-dd"
              type="date"
              placeholder="选择工艺最近更改日"
            />
          </el-col>
        </el-form-item>
        <!-- <el-form-item label="是否到货：" prop="isArrival"> -->
        <!-- <el-select v-model="product.isArrival" clearable placeholder="请选择是否到货">
                  <el-option
                    v-for="item in ArrivalList"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                   </el-option>
            </el-select> -->
        <!-- </el-form-item> -->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="restData()">取 消</el-button>
        <el-button type="primary" @click="append('product')">确 定</el-button>
      </div>
    </el-dialog>
    <el-dialog
      :visible.sync="dialogDelect"
    >
      <el-input
        :rows="2"
        v-model="textDelect"
        type="textarea"
        placeholder="请输入删除理由"/>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="delectClick">确 定</el-button>
      </div>
    </el-dialog>
    <el-dialog
      :visible.sync="dialogVueQr"
      width="400px"
    >
      <div style="text-align: center;height: 220px;">
        <vue-qr :size="191" :margin="0" :auto-color="true" :dot-scale="1" :text="appSrc" />
      </div>
    </el-dialog>
    <el-dialog
      :visible.sync="dialogImg"
      width="700px"
    >
      <div style="text-align: -webkit-center;height: 500px;">
        <div v-for="(item,index) in imgUrlList" :key="index" style="width: 250px;height: 200px;">
          <img v-if="item.type == 1" :src="item.imgUrl" :class="clickIndex == index ? 'imgClick' : ''" style="    width: 100%;" @click="clickOpen(index)">
          <div v-if="item.type == 2" style="    text-align: -webkit-center;padding-top:20px;" @click="download(item.imgUrl)">
            <div style="width: 80px;color: #3a8ee6;border-bottom: 1px #3a8ee6 solid;">
              下载PDF
            </div>

          </div>
        </div>
      </div>
    </el-dialog>
    <el-dialog
      :visible.sync="dialogsingle"
    >
      <el-form ref="form" :model="singleform" label-width="120px">
        <el-form-item label="是否外协：" prop="gender">
          <el-col :span="8">
            <el-select
              v-model="singleform.isoutsourcing"
              clearable
              placeholder="请选择是否外协"
              @change="changeOutsourcing"
            >
              <el-option
                v-for="item in valueList"
                :key="item.label"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-col>
        </el-form-item>
        <el-form-item v-if="isOutsourcing" label="选择外协人员：" prop="gender">
          <el-col :span="8">
            <el-select
              v-model="singleform.userId"
              clearable
              placeholder="请选择外协人员"
              @change="changeOutsourcing"
            >
              <el-option
                v-for="item in listUserP"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-col>
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="outsourcingClick">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import ViewSessions from './ViewSessions.vue'
import user from '../../api/acl/user.js'
export default {
  components: {
    ViewSessions
  },
  data() {
    return {
      dialogsingle: false,
      listUserP: [],
      singleform: {
        insideCode: '',
        outsourcingId: '',
        isoutsourcing: '0',
        userId: ''
      },
      isOutsourcing: false,
      valueList: [
        {
          value: '0',
          label: '否'
        },
        {
          value: '1',
          label: '是'
        }
      ],
      isNosingle: !(window.sessionStorage.getItem('department') == 5) && !(window.sessionStorage.getItem('department') == 7) && !(window.sessionStorage.getItem('department') == 8),
      isNoOutsourcing: !(window.sessionStorage.getItem('department') == 5),
      isRouter: !(window.sessionStorage.getItem('department') == 8 || window.sessionStorage.getItem('department') == 10),
      stpUrl: '',
      fileListStp: [],
      clickIndex: -1,
      pdfUrl: '',
      dialogImg: false,
      imgUrlList: [],
      dialogVueQr: false,
      appSrc: '',
      readonlyInput: false,
      imageUrl: '',
      imageUrlOne: '',
      dialogDelect: false,
      textDelect: '',
      total: 0, // 数据库中的总记录数
      page: 1, // 默认页码
      limit: 10, // 每页记录数
      ArrivalList: [
        {
          label: '0',
          value: '是'
        },
        {
          label: '1',
          value: '否'
        }
      ],
      validateRules: {
        endTime: [
          {
            type: 'date',
            required: true,
            message: '请选择计划完成时间：',
            trigger: 'change'
          }
        ],
        // requisition: [
        //   { required: true, trigger: 'change', message: '请输入请购单号' }
        // ],
        process: [
          { required: true, trigger: 'change', message: '请输入工序总览' }
        ],
        isArrival: [
          { required: true, trigger: 'blur', message: '请选择是否到货' }
        ],
        insideCode: [
          { required: true, trigger: 'change', message: '请输入内部编号' }
        ],
        cost: [
          { required: true, trigger: 'change', message: '请输入预估成本' }
        ]
      },
      fileList: [
      ],
      productList: [],
      dialogFormVisible: false,
      dialogFormValue: '',
      product: {
        cost: '',
        insideCode: '',
        process: '',
        requisition: '',
        isArrival: '',
        id: '',
        projectCode: '',
        code: '',
        specifications: '',
        amount: '',
        unit: '',
        date: '',
        purchase: '',
        purchaseItem: '',
        workmanshipDate: ''
      },
      searchInfo: {
        isComplete: '',
        productId: '',
        orderCode: ''
      }
    }
  },
  // 监听上面文本框搜索
  watch: {},

  created() {},
  mounted() {
    // this.searchInfo.productId = this.$route.query.id ? this.$route.query.id : ''
    this.searchInfo.orderCode = this.$route.query.insideCode ? this.$route.query.insideCode : ''
    console.log(this.searchInfo.productId)
    this.listUser()
    // if (this.$route.query.id) {
    this.listProduct()
    // } else {
    //   this.listProductForm()
    // }
  },
  methods: {
    single(row) {
      this.singleform.insideCode = row.insideCode
      this.singleform.outsourcingId = row.id
      this.singleform.isoutsourcing = '0'
      this.singleform.userId = ''
      this.isOutsourcing = false
      this.dialogsingle = true
    },
    outsourcingClick() {
      console.log(this.singleform.isoutsourcing)
      user
        .handoutProduct({
          id: this.singleform.outsourcingId,
          productId: this.singleform.outsourcingId,
          productCode: this.singleform.insideCode,
          isAssist: this.singleform.isoutsourcing,
          userId: this.singleform.isoutsourcing == '1' ? this.singleform.userId : '3'
        })
        .then((response) => {
          console.log(response)
          this.dialogsingle = false
          this.$message({
            message: '分配成功',
            duration: 1000
          })
          // if (this.$route.query.id) {
          this.listProduct()
          // } else {
          //   this.listProductForm()
          // }
        })
    },
    listUser() {
      user
        .listUser({
          department: '5',
          limit: 10000,
          page: 1
        })
        .then((response) => {
          console.log(response)
          for (let i = 0; i < response.list.length; i++) {
            const obj = {}
            if (response.list[i].fullName != '' && response.list[i].fullName != null && response.list[i].fullName != undefined) {
              obj.value = response.list[i].id
              obj.label = response.list[i].fullName
              this.listUserP.push(obj)
            }
          }
        })
    },
    changeOutsourcing(val) {
      console.log(val)
      if (val == 0) {
        // 不是外协
        this.isOutsourcing = false
      } else {
        // 外协
        this.isOutsourcing = true
      }
    },
    seeOutsourcing(row) {
      this.$router.push({
        path: '/outsourcing',
        query: { productCode: row.insideCode, productId: row.id }
      })
    },
    onRemoveStp(file, fileList) {
      console.log(file, fileList)
      this.stpUrl = ''
    },
    onRemove(file, fileList) {
      console.log(file, fileList)
      this.pdfUrl = ''
    },
    /**
 * @deprecated 下载文件
 * @param {string} url
 * @param {string} filename
 */
    handleFileDownload(url, link, filename) {
      // 创建 a 标签
      const a = document.createElement('a')
      a.href = link
      a.download = filename + url.split('.')[url.split('.').length - 1] + '.' + url.split('.')[url.split('.').length - 1]
      a.click()
    },

    /**
 * @deprecated 处理 pdf url，使其不在浏览器打开
 * @param {string} url
 */
    handlePdfLink(url, filename) {
      fetch(url, {
        method: 'get',
        responseType: 'arraybuffer'
      })
        .then(function(res) {
          if (res.status !== 200) {
            return res.json()
          }
          return res.arrayBuffer()
        })
        .then((blobRes) => {
    	// 生成 Blob 对象，设置 type 等信息
          const e = new Blob([blobRes], {
            type: 'application/octet-stream',
            'Content-Disposition': 'attachment'
          })
          // 将 Blob 对象转为 url
          const link = window.URL.createObjectURL(e)
          this.handleFileDownload(url, link, filename)
        }).catch(err => {
          console.error(err)
        })
    },
    clickOpen(val) {
      if (val == this.clickIndex) {
        this.clickIndex = -1
      } else {
        this.clickIndex = val
      }
    },
    download(val) {
      // const aLink = document.createElement('a')
      // aLink.href = val
      // aLink.click()
      window.open(val)
      // this.handlePdfLink(val, 'PDF')
    },
    listImageFolder(val) {
      user.listImageFolder({
        productId: val
      }).then((response) => {
        console.log(response)
        this.imageUrl = response[0] ? response[0].imgUrl : ''
        this.imageUrlOne = response[1] ? response[1].imgUrl : ''
        this.pdfUrl = response[2] ? response[2].imgUrl : ''
        this.stpUrl = response[3] ? response[3].imgUrl : ''
      })
    },
    myUploadStp(param) {
      const formData = new FormData()
      formData.append('file', param.file) // 文件（图片）

      user.objectLinkPdf(formData).then((response) => {
        this.stpUrl = response
        this.fileListStp = []
        this.fileListStp.push({
          'name': param.file.name,
          'url': response
        })
      })
    },
    myUploadPDF(param) {
      const formData = new FormData()
      formData.append('file', param.file) // 文件（图片）

      user.objectLinkPdf(formData).then((response) => {
        this.pdfUrl = response
        this.fileList = []
        this.fileList.push({
          'name': param.file.name,
          'url': response
        })
      })
    },
    removeImgOne() {
      this.imageUrlOne = ''
    },
    myUploadImgOne(param) {
      const formData = new FormData()
      formData.append('file', param.file) // 文件（图片）

      user.objectLinkPdf(formData).then((response) => {
        this.imageUrlOne = response
      })
    },
    removeImg() {
      this.imageUrl = ''
    },
    myUploadImg(param) {
      const formData = new FormData()
      formData.append('file', param.file) // 文件（图片）

      user.objectLinkPdf(formData).then((response) => {
        this.imageUrl = response
      })
    },
    addRequisition(row) {
      this.$router.push({
        path: '/requisitionList',
        query: { code: row.purchaseRequisition, productCode: row.insideCode, id: row.id }
      })
    },
    tableRowClassName({ row, rowIndex }) {
      if (row.deleteFlag == 1) {
        return 'warning-row'
      }
      return ''
    },
    delectClick() {
      if (this.textDelect == '') {
        this.$message({
          message: '请输入删除理由',
          duration: 1000
        })
        return
      }
      user.deleteProduct({
        deleteFlag: 1,
        id: this.delectId,
        deleteRemark: this.textDelect
      }).then((response) => {
        this.delectId = ''
        this.textDelect = ''
        this.dialogDelect = false
        this.$message({
          message: '删除成功',
          duration: 1000
        })
        // if (this.$route.query.id) {
        this.listProduct()
        // } else {
        //   this.listProductForm()
        // }
      })
    },
    delect(val) {
      this.delectId = val.id
      this.textDelect = ''
      this.dialogDelect = true
    },
    fetchData(val) {
      this.page = val
      // if (this.$route.query.id) {
      this.listProduct()
      // } else {
      //   this.listProductForm()
      // }
    },
    listProductForm() {
      user
        .listProductForm({
          insideCode: this.searchInfo.productId, // 产品编号
          status: this.searchInfo.isComplete, // 0-进行中1-已完成
          limit: this.limit,
          page: this.page
        })
        .then((response) => {
          console.log(response)
          this.productList = response.list
          this.total = response.total
        })
    },
    // 产品列表
    listProduct() {
      user
        .listProduct({
          orderId: this.$route.query.id,
          orderCode: this.searchInfo.orderCode ? this.searchInfo.orderCode : '', // 订单编号
          productCode: this.searchInfo.productId, // 产品编号
          status: this.searchInfo.isComplete, // 0-进行中1-已完成
          limit: this.limit,
          page: this.page
        })
        .then((response) => {
          console.log(response)
          this.productList = response.list
          this.total = response.total
        })
    },
    insertProduct(val, val2) {
      if (val2 == 'add') {
        // 新增成功
        user
          .insertProduct(val)
          .then((response) => {
            // if (this.$route.query.id) {
            this.listProduct()
            // } else {
            //   this.listProductForm()
            // }
            this.$message({
              message: '新增成功',
              duration: 1000
            })
          })
          .catch((err) => {
            console.log(err)
          })
        this.dialogFormVisible = false
      } else if (val2 == 'upload') {
        user
          .updateProduct(val)
          .then((response) => {
            // if (this.$route.query.id) {
            this.listProduct()
            // } else {
            //   this.listProductForm()
            // }
            this.$message({
              message: '修改成功',
              duration: 1000
            })
          })
          .catch((err) => {
            console.log(err)
          })
        // 修改成功
        this.dialogFormVisible = false
      }
    },
    closeDialog() {
      this.product = {
        cost: '',
        insideCode: '',
        projectCode: '',
        code: '',
        specifications: '',
        amount: '',
        unit: '',
        date: '',
        purchase: '',
        purchaseItem: '',
        workmanshipDate: '',
        process: '',
        requisition: '',
        isArrival: '',
        id: ''
      }
      this.imageUrl = ''
      this.imageUrlOne = ''
      this.pdfUrl = ''
      this.stpUrl = ''
      this.fileList = []
      this.fileListStp = []
      this.$refs.product.resetFields()
    },
    append(val) {
      this.$refs[val].validate((valid) => {
        if (valid) {
          if (
            this.product.id == '' ||
            this.product.id == null ||
            this.product.id == undefined
          ) {
            this.insertProduct(
              {
                cost: this.product.cost,
                insideCode: this.product.insideCode,
                process: this.product.process,
                purchaseRequisition: this.product.requisition,
                projectCode: this.product.projectCode,
                code: this.product.code,
                specifications: this.product.specifications,
                amount: this.product.amount,
                unit: this.product.unit,
                date: this.product.date,
                purchase: this.product.purchase,
                purchaseItem: this.product.purchaseItem,
                workmanshipDate: this.product.workmanshipDate,
                imageUrl: [
                  {
                    'type': 1,
                    'imgUrl': this.imageUrl
                  },
                  {
                    'type': 1,
                    'imgUrl': this.imageUrlOne
                  },
                  {
                    'type': 2,
                    'imgUrl': this.pdfUrl
                  },
                  {
                    'type': 3,
                    'imgUrl': this.stpUrl
                  }
                ]
              },
              'add'
            )
          } else {
            this.insertProduct(
              {
                cost: this.product.cost,
                insideCode: this.product.insideCode,
                process: this.product.process,
                purchaseRequisition: this.product.requisition,
                projectCode: this.product.projectCode,
                code: this.product.code,
                specifications: this.product.specifications,
                amount: this.product.amount,
                unit: this.product.unit,
                date: this.product.date,
                purchase: this.product.purchase,
                purchaseItem: this.product.purchaseItem,
                workmanshipDate: this.product.workmanshipDate,
                id: this.product.id,
                imageUrl: [
                  {
                    'type': 1,
                    'imgUrl': this.imageUrl
                  },
                  {
                    'type': 1,
                    'imgUrl': this.imageUrlOne
                  },
                  {
                    'type': 2,
                    'imgUrl': this.pdfUrl
                  },
                  {
                    'type': 3,
                    'imgUrl': this.stpUrl
                  }
                ]
              },
              'upload'
            )
          }
        }
      })
    },
    restData() {
      this.dialogFormVisible = false
      this.dialogFormValue = ''
    },
    selected(val) {
      this.searchInfo = val
      this.page = 1
      // if (this.$route.query.id) {
      this.listProduct()
      // } else {
      //   this.listProductForm()
      // }
    },
    add() {
      this.dialogFormVisible = true
      this.readonlyInput = false
      this.fileList = []
      this.dialogFormValue = '新增产品'
    },
    seeVueQr(val) {
      this.dialogVueQr = true
      this.appSrc = val.insideCode + ''
    },
    seeOrder(val) {
      user.listImageFolder({
        productId: val.id
      })
        .then((response) => {
          console.log(response)
          if (response.length > 0) {
            this.dialogImg = true
            this.imgUrlList = response
          } else {
            this.$message({
              message: '暂无可以查看的文件',
              duration: 1000
            })
          }
        })
    },
    seeDispatch(val) {
      this.$router.push({ path: '/dispatchList', query: { id: val.id }})
    },
    seeDeleteItem(val) {
      this.dialogFormVisible = true
      this.dialogFormValue = '查看产品'
      this.readonlyInput = true
      this.listImageFolder(val.id)
      this.product = {
        insideCode: val.insideCode,
        cost: val.cost,
        projectCode: val.projectCode,
        code: val.code,
        specifications: val.specifications,
        amount: val.amount,
        unit: val.unit,
        date: val.date,
        purchase: val.purchase,
        purchaseItem: val.purchaseItem,
        workmanshipDate: val.workmanshipDate,
        process: val.process,
        requisition: val.purchaseRequisition,
        id: val.id
        // isArrival:'',
      }
    },
    upload(val) {
      this.dialogFormVisible = true
      this.readonlyInput = false
      this.dialogFormValue = '修改产品'
      this.listImageFolder(val.id)
      this.product = {
        insideCode: val.insideCode,
        cost: val.cost,
        projectCode: val.projectCode,
        code: val.code,
        specifications: val.specifications,
        amount: val.amount,
        unit: val.unit,
        date: val.date,
        purchase: val.purchase,
        purchaseItem: val.purchaseItem,
        workmanshipDate: val.workmanshipDate,
        process: val.process,
        requisition: val.purchaseRequisition,
        id: val.id
        // isArrival:'',
      }
    }
  }
}
</script>
<style lang="scss" scoped>
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
  border: 1px #dcdfe6 solid;
}
.avatar {
  width: 178px;
  height: 178px;
  display: block;
}
.el-table .warning-row {
  background: #ff02027a;
}
// img{
//         width: 700px;
//         overflow: hidden;
//         margin: 0 auto;
//     }
 #img img{
        width: 100%;
        transition:all 2s;/*图片放大过程的时间*/
        position: relative;
    }
    .imgClick{
        cursor: crosshair;
        transform: scale(3);  /*以y轴为中心旋转*/
    }

 div {
   b{
          display: block;
    position: absolute;
left: 176px;
    top: -10px;
    width: 18px;
    height: 18px;
    border-radius: 100%;
    background: #fff;
    color: #333;
    text-align: center;
    line-height: 16px;
    font-size: 18px;
    z-index: 10;
    border: 1px solid #93a9ca;
    cursor: pointer;
    }
 }
//      .imageUrlOne {
//        b{
//           display: block;
//     position: absolute;
// left: 176px;
//     top: -10px;
//     width: 18px;
//     height: 18px;
//     border-radius: 100%;
//     background: #fff;
//     color: #333;
//     text-align: center;
//     line-height: 16px;
//     font-size: 18px;
//     z-index: 10;
//     border: 1px solid #93a9ca;
//     cursor: pointer;
//     }
//      }
</style>
